import { useCallback, useState } from 'react'
import Child from './Child'

const Parent = () => {
  const [count, setCount] = useState(0)
  // 每次render此函数都会重新初始化,useCallback可以缓存函数引用
  const inc = useCallback((step) => {
    console.log('inc函数执行了')
    setCount((count) => count + step)
  }, [])
  console.log('parent render')
  return (
    <div>
      <span>count: {count}</span>
      <Child inc={inc} />
    </div>
  )
}

export default Parent
